package com.service.business.order.controller;

import com.service.business.framework.log.RequestLog;
import com.service.business.order.controller.rep.*;
import com.service.business.order.controller.req.OrderComboPageReq;
import com.service.business.order.controller.req.OrderLockReq;
import com.service.business.order.service.OrderProductLockComboService;
import com.service.core.rest.BaseController;
import com.service.core.rest.response.BaseResponse;
import com.service.core.rest.response.OneResponse;
import com.service.core.rest.response.PageResponse;
import com.service.dao.enums.CoinsEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController()
@RequestMapping("order-product-lock-combo")
@Api(tags = "锁仓（存币）订单相关")
public class OrderProductLockComboController extends BaseController {

	@Autowired
	private OrderProductLockComboService orderProductLockComboService;

	@ApiOperation("立即下单:存币(锁仓)套餐")
	@RequestLog("立即下单:存币(锁仓)套餐")
	@PostMapping("order-lock/{lockComboId}")
	public BaseResponse orderLockCombo(@PathVariable("lockComboId") Integer lockComboId, @RequestBody @Validated OrderLockReq orderReq) {
		orderProductLockComboService.placeLockOrder(lockComboId, orderReq);
		return successBaseResponse();
	}

	@ApiOperation("支付详情")
	@RequestLog("支付详情")
	@PostMapping("pay-detail/{lockNo}")
	public OneResponse<BaseOrderLockRep> payInfo(@PathVariable("lockNo") String lockNo) {
		return successQueryOneResponse(orderProductLockComboService.getOrderPayInfo(lockNo));
	}

	@ApiOperation("订单分页:算力套餐")
	@RequestLog("订单分页:算力套餐")
	@PostMapping("list")
	public PageResponse<OrderLockComboPageRep> orderList(@RequestBody OrderComboPageReq request) {
		return successQueryPageResponse(orderProductLockComboService.page(request));
	}

	@RequestLog("取消订单")
	@ApiOperation("取消订单")
	@PostMapping("cancel/{lockNo}")
	public BaseResponse cancelOrder(@ApiParam @PathVariable("lockNo") String lockNo) {
		orderProductLockComboService.cancelLockOrder(lockNo);
		return successBaseResponse();
	}

	@RequestLog("用户锁仓统计")
	@ApiOperation("用户锁仓统计")
	@PostMapping("assets-lock/{coinsName}")
	public OneResponse<MemberLockAssetsRep> assetsLock(@ApiParam @PathVariable("coinsName") CoinsEnum coins) {
		return successQueryOneResponse(orderProductLockComboService.assetsLock(coins));
	}
}
